package aobing;


import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * CollectionTest
 *
 * @author Syzer
 * @Description
 * @Date 2021/7/1 20:20
 */
public class CollectionTest {

    public static void vectorTest() {
        ExecutorService executorService = Executors.newCachedThreadPool();
        Vector<Integer> v = new Vector<Integer>(){{
            add(1);
            add(2);
        }};
        for(int i = 0;i < 4;i++) {
            executorService.execute(new Runnable() {
                @Override
                public void run() {
                    while(true) {
//                        synchronized (v) {
                            int index = v.size() - 1;
                            if (index >= 0) {
                                System.out.println("删除");
                                v.remove(index);
                            }
//                        }
                    }
                }
            });
        }
        for(int i = 0;i < 3;i++) {
            executorService.execute(new Runnable() {
                @Override
                public void run() {
                    while (true) {
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        System.out.println("添加");
                        v.add(1);
                    }
                }
            });
        }
        executorService.shutdown();
    }

    public static void main(String[] args) {
//        vectorTest();
        Hashtable<Object, Object> hashtable = new Hashtable<>();
        hashtable.put("123", "123");
        Iterator<Map.Entry<Object, Object>> iterator = hashtable.entrySet().iterator();
        ArrayList<Object> objects = new ArrayList<>();
        objects.add("123");
        objects.add("123");
        objects.add("123");
        for(int i = 0;i < objects.size();i++) {
            System.out.println(objects.get(i));
            objects.add(123);
        }
    }
}
